export default {
  namespaced: true,
  state () {
    return {
      list: [
        {
          name: '诸葛亮',
          price: 1000,
          num: 1,
          checked: false
        },
        {
          name: '蔡文姬',
          price: 1500,
          num: 1,
          checked: false
        },
        {
          name: '妲己',
          price: 2000,
          num: 1,
          checked: false
        },
        {
          name: '鲁班',
          price: 2200,
          num: 1,
          checked: false
        }
      ]
    }
  },
  mutations: {
    getList (state, payload) {
      state.list = payload
    },
    amendNum (state, payload) {
      state.list[payload.index].num = payload.num
    },
    inputChange (state, payload) {
      state.list[payload].checked = !state.list[payload].checked
    },
    isAllFn (state, payload) {
      // console.log(payload);
      state.list.forEach(item => item.checked = payload)
    },
    delbutton(state, payload) {
      state.list.splice (payload, 1)
    }

  },
  getters: {
    priceSum: state => state.list.filter(item => item.checked)
    .reduce((sum, item) => sum + item.price * item.num, 0),
    allClick: state => state.list.every(item => item.checked)
  }
}
